package backtrack

// 给一个整数数组，元素各不相同，返回所有子集
func subsets(nums []int) [][]int {
	res := [][]int{}
	path := []int{}

	var dfs func(start int)
	dfs = func(start int) {
		tmp := make([]int, len(path))
		copy(tmp, path)
		res = append(res, tmp)
		if (start >= len(nums)) {
			return
		}
		for i := start; i < len(nums); i++ {
			path = append(path, nums[i])
			dfs(i + 1)
			path = path[:len(path) - 1]
		}
	}
	dfs(0)
	return res
}